<?php
	if( ! isset ($formName) )
		$formName = "adminForm";
?>
<table class="tablelist joblist" cellpadding="5" cellspacing="5">
   	<thead>	    		
		<tr>	
			<?php if(isset($this->pagination)){?>				
			<td width="20" class="first sectiontableheader">
				<?php echo JText::_( '#' ); ?>
			</td>
			
			
			<td width="20" class="sectiontableheader">
				<input type="checkbox" name="toggle" value="" onclick="jalist_show_box_action(this, '<?php echo $formName;?>');checkAlls(document.<?php echo $formName;?>, <?php echo count($this->all_items); ?>);" />
			</td>
			<?php }?>
			<?php for($i = 0, $n = count($this->fieldlist); $i < $n; $i++ ){
				$field = $this->fieldlist[$i];
				if($field->is_sortable){
					
					$header = JHTML::_('grid.sort',   JText::_($field->label), $field->sort_field_name, @$this->lists['filter_order_Dir'], @$this->lists['filter_order'] );
				} else {
					$header = JText::_($field->label);
				}
				?>
				<td class="<?php if ($i==$n-1) echo 'last'; ?> sectiontableheader">
					<?php echo  $header; ?>
				</td>
				<?php
			}?>			           
		</tr>
	</thead>
	
	<tfoot>			
		<tr>
			<td colspan="<?php echo isset($this->fieldlist)?count($this->fieldlist)+1:1; ?>" class="jobs-pagination">			
				<?php if(isset($this->all_items) && isset($this->pagination) ){?>
				
					<?php if(!JRequest::getVar('ajax')){?>
						<div class="jobs-pagination clearfix"><?php echo $this->pagination->getListFooter(); ?></div>
					<?php } else {?>
						<div class="jobs-pagination clearfix">
							<div class="limit">
								<label for="limit"><?php echo JText::_("Display num")?></label>
								<?php echo $this->getListLimit(JRequest::getInt('limit', $jbconfig['posts']->get('display_num'))); ?>
							</div>
					
						  	<?php echo $this->pagination->getPagesLinks(); ?>
							<?php if ($this->pagination->getPagesLinks()!='') {?>
								<div class="counter">
									<?php echo JText::_('Page').' '.(JRequest::getVar('limitstart',0)/$this->pagination->limit+1).' '.JText::_('of').' '.ceil($this->pagination->total/$this->pagination->limit);?>
								</div>
							<?php }?>
						</div>
					<?php }?>
					
				<?php }?>
			
			

			</td>
		</tr>
	</tfoot>
			
	<?php if(isset($this->all_items)){?>
	<tbody>
   	<?php
   	$items = $this->all_items;
   	$k = 0;
   	$orderNo = 0;
   	$currentTable = '';
   	
   	/*$search_cat_id = JRequest::getVar('cat_id', '');
   	if($search_cat_id) $search_cat_id = explode(',', $search_cat_id);*/
   	
   	for($i = 0, $n = count($this->all_items); $i < $n; $i++, $orderNo++)
   	if (isset($items[$i]->id))
   	{
   		$item = $items[$i];
//   		JFilterOutput::objectHTMLSafe( $item );	    

   		if(is_array($item->cat_id_tmp)) $cats = implode(',', $item->cat_id_tmp);
   		else $cats = $item->cat_id_tmp;
		$cat_names = getCategories($cats);
		$cats = explode(',',$cat_names);	
		
		if(is_array($item->location_id_tmp)) $locations = implode(',', $item->location_id_tmp);
   		else $locations = $item->location_id_tmp;
   		$location_names = getLocation($locations);
   		$locations = explode(',',$location_names);
		
   		$class = '';	
   		
   		if($item->is_hotjob==1) $class = "class='hot'";
   		if ($i==0)
      		$classname = 'first sectiontableentry'.($k+1);
      	elseif ($i==$n-1)
      		$classname = 'last sectiontableentry'.($k+1);
      	else 
      		$classname = 'sectiontableentry'.($k+1);
   		?>
   		<tr class="<?php echo $classname; ?>">
   			<?php if(isset($this->pagination)){?>
       		<td align="center" <?php echo ($item->is_hotjob==1)?'class="first hot"':'class="first"';?>>
       			<?php echo $this->pagination->getRowOffset($i); ?>
       		</td>
       		
       		<td align="center" <?php echo ($item->is_hotjob==1)?'class="first hot"':'class="first"';?>>
       			<input title="<?php echo JText::_('Click here to view more jobs')?>" id="cb<?php echo $i?><?php echo $formName;?>" type="checkbox" onclick="isChecked(this.checked); jalist_show_box_action(this, '<?php echo $formName;?>'); " value="<?php echo $item->id; ?>" name="cid[]"/>
       		</td>
       		<?php }?>
       		<?php
					
	                for($ii = 0, $nn = count($this->fieldlist); $ii < $nn; $ii++ ){
	                	$field = $this->fieldlist[$ii];
                        $field_name = $field->field_name;
                                                
                        $width_column = ($field->column_width!=0)?"width=\"".$field->column_width."%\"":"";
                        $prefix = '';
	                	$td_classname = '';
	                	if ($ii==$nn-1)
	                		$prefix = 'last ';
	                	if($item->is_hotjob==1)
	                		$prefix = $prefix.'hot';
	                	if ($prefix!='')
	                	$td_classname = 'class="'.$prefix.'"';
	                	
	                	$align="";                        
		                if($field->field_type == "boolean" ){
		                    $align = "align='center'";
		                    $text = $this->getToggleLink($field_name, $item);
		                }
			            
	                	if($field_name == 'cat_id'){
	                	
	                	?>
	                	<!-- Apply for Categories -->
	                		<td <?php echo $align; ?> <?php //echo $nowrap; ?>  <?php echo $td_classname;?> <?php echo $width_column; ?>>
				            	<span class="ja-job-category">
			           			<?php if($cats) { ?>
									<?php foreach ($cats as $d=>$cat) { ?>
			            				<a href="<?php echo JRoute::_('index.php?option=com_jajobboard&view=jajobs&layout=filter_job_list&cat_id='.$cat)?>" title="<?php echo $cat?>"><?php echo $cat?></a><?php if($d<count($cats)-1) echo ', '?>
			            			<?php } ?>				            
			            		<?php } ?>
			        			</span>
				            </td>
	                	<?php 
	                	}
	                	elseif($field_name == 'location_id'){?>
	                	<!-- Apply for Locations -->
	                		<td <?php echo $align; ?> <?php //echo $nowrap; ?>  <?php echo $td_classname;?> <?php echo $width_column; ?>>
				            	<span class="ja-job-location">
									<?php foreach ($locations as $d=>$location) { ?>
			            				<a href="<?php echo JRoute::_('index.php?option=com_jajobboard&view=jajobs&layout=filter_job_list&location_id='.$location)?>" title="<?php echo $location?>"><?php echo $location?></a><?php if($d<count($locations)-1) echo ', '?>
			            			<?php } ?>	
								</span>
				            </td>
	                		
	                	<?php 
	                	}
	                	else{
		                	$added_note = '';
		                	if (isset($this->item_notes[$item->id])&&($this->item_notes[$item->id]->user_id==$user->id)){
	            				$added_note = '<span class="note"><img src="components/com_jajobboard/images/icons/jobs/note.png" alt="'.JText::_('Added Note!').'" title="'.JText::_('Added Note!').'"/>'.JText::_('Added Note').'</span>'  ;      			
	//							$added_note = '<span class="note">'.JText::_('Added Note').'</span>'  ;
		                	}
	            			
	                        if (is_array($item->$field_name))
	                        	$item->$field_name = implode(',',$item->$field_name);
	                        $item->$field_name = trim($item->$field_name);
	                        $text = $field->truncate_length?SmartTrim::trim($item->$field_name,0,$field->truncate_length):$item->$field_name;
		                	$text = $field->clean_format?JFilterOutput::cleanText($text):$text;
		                	 	
		                	
		                	if ($field->field_type=='URL'&&!$field->linked)
		                	{
			                	if (substr($item->$field_name,0,7)!='http://')
			                		$value_link = 'http://'.$item->$field_name;
			                	else 
			                		$value_link = $item->$field_name;
			                	$text = '<a href="'.$value_link.'" target="_blank">'.$text.'</a>';
			                }	                	
		                	
		                   	//$nowrap = $field->no_wrap ? "":"nowrap=\"nowrap\"";	   
				    		$job_detail = '';
			                if ($jbconfig['posts']->get('posts_show_job_type') && $item->cat_id_tmp){
			                	if (is_array($item->cat_id))
			                		$item->cat_id = implode(',',$item->cat_id);
			                	if (is_array($item->cat_id_tmp))
			                		$item->cat_id_tmp = implode(',',$item->cat_id_tmp);	
			                	$cat_names = getCategories($item->cat_id_tmp);
			                	$job_detail= '<b>'.JText::_('Category').': </b>'.$cat_names;
			                }
			                if ($jbconfig['posts']->get('posts_show_description')){
			                	$max_length = $jbconfig['posts']->get('posts_description_chars')? $jbconfig['posts']->get('posts_description_chars'):150;
			                	$item->job_detail = htmlspecialchars_decode(substr(SmartTrim::trim($item->job_detail,0,$max_length),0,$max_length));
	//		                	$filter	= new JFilterInput( '', '', 1, 1);
	//		                	$item->job_detail = $filter->clean ( $item->job_detail );
			                	$job_detail .= '<br /><b>'.JText::_('Description').': </b>'.$item->job_detail;
			                }
			                if ($jbconfig['posts']->get('posts_show_posted_by') && $item->user_id){	
	//		                	$creator = 	JFactory::getUser($item->user_id);
			                	$job_detail.= '<br /><b>'.JText::_('Created by').': </b>'.$item->user_id;
			                }
			                
		                    if ($jbconfig['posts']->get('postsshow_days_elapsed')){
			                	$job_detail.= '<br /><b>'.JText::_('Created date').': </b>'.$item->effected_date;
			                }                        
		                    if($field->linked){?>
		                       <td <?php echo $align; ?> <?php //echo $nowrap; ?>  <?php echo $td_classname;?> <?php echo $width_column; ?>>
		                       		<?php 
		                       			$alias = JFilterOutput::stringURLSafe(trim($item->$field_name));
		                                if($field->field_name == 'title' && getCurrentUserType() == JBJOB_SEEKER_USER){ // First field
		                                    if ($this->check_stared($item->id))
		                                		echo $this->getToggleLink('is_starred', $item,true); 
		                                	else 
		                                		echo $this->getToggleLink('is_starred', $item,false); 
		                                	
		
		                                }
		                              ?>
		                              <?php if ($job_detail!='') {?>
		                           <span class="editlinktip hasTip" title="<?php echo htmlspecialchars($job_detail);?>">
		                           <?php } else { ?>
		                           <span>
		                           <?php } ?>
		                           <?php if ($field->is_bold) echo '<strong>'; ?>		                          
		                              <a href="<?php echo JRoute::_('index.php?option='. JBCOMNAME .'&view=jajobs&layout=jaview&cid[]='.$item->id.'&alias='.$alias.'&Itemid='.$this->Itemid); ?>"  <?php echo $class;?>><?php echo $text; ?></a>
		                              <?php if ($field->is_bold) echo '</strong>'; ?>
		                              </span>
		                              
		                              <?php if( $ii+1 == $nn ) echo $added_note;?>
		                       </td>
	                       <?php
		                   } else { 		                   		
		                   		if( $field->field_type == "DATE_CAL" || $field->field_type == "DATE"){
		                    		$format = $jbconfig['general']->get("format_date", "%Y-%m-%d");
		                    		 $format = "%Y-%m-%d"; 
		                    		$format = str_replace("%", "", $format);	
		                    		if( strpos($text, " ") !== false && $jbconfig['general']->get("posts_show_published_date", "1") == "0" )
		                    			$text = date($format, strtotime($text));
		                    		
		                    	}
		                       ?>
		                       <td <?php echo $align; ?> <?php //echo $nowrap; ?>  <?php echo $td_classname;?> <?php echo $width_column; ?>>
		                        <?php if ($field->is_bold) echo '<strong>'; ?>
		                            <?php echo  $text; ?>
		                        <?php if ($field->is_bold) echo '</strong>'; ?>
		                        
		                        <?php if( $ii+1 == $nn ) echo $added_note;?>
		                      	</td>
		                       <?php
		                   }
	                	}
               }
               ?>
               
       	</tr>            	      	
   	<?php
   		$k = 1 - $k;
	}
   	?>
   	
   	</tbody>
   	<?php }?>
</table>


<?php if (!isset($jbconfig['feeds']) || $jbconfig['feeds']->get('show_feed', 1)) {?>
<div class="moduletable rsslink">
	<?php $Itemid_feed = get_Itemid(array('option'=>'com_jajobboard', 'view'=>'jafeeds'))?>
	<a href="<?php echo JRoute::_("index.php?option=com_jajobboard&view=jafeeds&layout=guide&Itemid=".$Itemid_feed); ?>"><?php echo JText::_('Jobs via RSS '); ?><img alt="RSS help" src="<?php echo JURI::root()."components/com_jajobboard/images/rss.gif"; ?>" /></a>
</div>	   
<?php } ?>


<div id="ja-box-action" class="sectiontableheader">
	<div class="jalist-count">
		<?php echo JText::_('You have selected')?> <span id="count-selection">0</span> <?php echo JText::_('items')?>
	</div>
	<div class="jalist-actions-right">
		<ul>
			<li>
				<img title="<?php echo JText::_('View detail'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Preview-16x16.png' ?>" alt="<?php echo JText::_('View detail'); ?>" />
				
				<a href="javascript:submitbutton_multi_view('multi_view','<?php echo count($this->all_items); ?>', '<?php echo $formName;?>')">
					<span style="vertical-align: top !important;"><?php echo JText::_('View detail'); ?></span>
				</a>&nbsp;&nbsp;
				
				<?php if (getCurrentUserType() == JBEMPLOYER_USER  && JRequest::getVar("layout") == "myjobs" && JRequest::getVar("employerid", "") == "") { ?>
				<img title="<?php echo JText::_('Delete'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/del.gif' ?>" alt="<?php echo JText::_('Delete'); ?>" />
				<a href="javascript:submitbutton_multi_view('multi_delete','<?php echo count($this->all_items); ?>', '<?php echo $formName;?>')">
					<span style="vertical-align: top !important;"><?php echo JText::_('Delete'); ?></span>
				</a>
				<?php } ?>
			</li>
			<?php if(getCurrentUserType() == JBEMPLOYER_USER){?>
			<li>
	     		<img title="<?php echo JText::_('Set as Favorite'); ?>" src="<?php echo JURI::base().'components/com_jajobboard/images/Favorites-16x16.png' ?>" alt="<?php echo JText::_('Favorite'); ?>" />
	     		&nbsp;
				<a href="javascript:submitbuttonGeneral('multi_starred','<?php echo count($this->all_items); ?>')">
					<span style="vertical-align: top !important;"><?php echo JText::_('Favorite'); ?></span>
				</a>
			</li>
			<?php }?>
		</ul>
	</div>
</div>
<div style="clear:both"></div>